package com.feng.study.demo.stream;

import com.feng.study.model.Product;
import com.google.common.collect.Lists;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: Zeng ShaoYong
 * @Date: 2022-04-27
 * @Description:
 */
public class StreamMapDemo {
    public static void main(String[] args) {
        List<Product> products = Lists.newArrayList();
        products.add(new Product().setProductId("001").setPrice("100"));
        products.add(new Product().setProductId("001").setPrice("99"));
        products.add(new Product().setProductId("001").setPrice("88"));
        products.add(new Product().setProductId("002").setPrice("88"));

        Map<String, List<String>> priceByProductId = products.stream()
                .collect(Collectors.groupingBy(Product::getProductId,
                        Collectors.mapping(Product::getPrice, Collectors.toList())));
        products.stream()
                .collect(Collectors.toMap(Product::getProductId, item->item));

        products.stream().map(Product::getPrice).collect(Collectors.toList());
        products.stream().collect(Collectors.mapping(Product::getPrice,Collectors.toList()));
    }
}
